<template>
    <div>
        <div id="searchBox">
            <el-form :inline="true" style="margin: 10px">
                <el-form-item label="操作模块:">
                    <el-input placeholder="请输入操作模块" v-model="queryParam.operation" clearable></el-input>
                </el-form-item>
                <el-form-item label="操作详细:">
                    <el-input placeholder="请输入操作详细" v-model="queryParam.content" clearable></el-input>
                </el-form-item>
                <el-form-item>
                    <el-date-picker v-model="value1" type="daterange" range-separator="至" start-placeholder="开始日期"
                        end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>
                <el-button type="primary" @click="searchQuery">查询</el-button>
                <el-button @click="searchReset">重置</el-button>
                <el-button type="text" style="margin-left:10px" id="closeSearchBtn" @click="closeSearch">
                    {{ word }}
                    <i :class="showAll ? 'el-icon-arrow-up ' : 'el-icon-arrow-down'"></i>
                </el-button>
                <el-form-item label="操作员:" style="margin-left: 15px;">
                    <el-input placeholder="请输入操作员账号或姓名" v-model="queryParam.loginName" clearable></el-input>
                </el-form-item>
                <el-form-item label="操作IP:" style="margin-left: 20px;">
                    <el-input placeholder="请输入操作IP" v-model="queryParam.clientIp" clearable></el-input>
                </el-form-item>
                <el-form-item label="操作状态">
                    <el-select v-model="queryParam.status" placeholder="请选择">
                        <el-option label="成功" value="0"></el-option>
                        <el-option label="失败" value="1"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
        </div>
        <div class="table">
            <!-- table区域 -->
            <el-table ref="multipleTable" :data="logList" tooltip-effect="dark" border style="width: 97%;margin:10px;">
                <el-table-column type="index" width="110" label="#"></el-table-column>
                <el-table-column prop="operation" label="操作模块"></el-table-column>
                <el-table-column prop="content" label="操作详细"> </el-table-column>
                <el-table-column prop="loginName" label="操作员账号"> </el-table-column>
                <el-table-column prop="userName" label="操作员姓名"> </el-table-column>
                <el-table-column prop="status" label="操作状态">
                    <template slot-scope="scope">
                        {{ scope.row.status === 0 ? "成功" : "失败" }}    
                    </template>     
                </el-table-column>
                <el-table-column prop="clientIp" label="操作IP"> </el-table-column>
                <el-table-column prop="createTime" label="操作时间">
                    <template slot-scope="scope">
                        {{ formatDate(scope.row.createTime) }}    
                    </template>    
                </el-table-column>
            </el-table>
            <el-pagination style="float: right;margin-right: 50px;margin-top: 10px;" @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="current" :page-sizes="[5, 10, 15, 20]" :page-size="pageSize" class="page"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import logApi from "@/api/system/log"

export default {
    data() {
        return {
            // 查询条件
            queryParam: {},
            logList: [],
            multipleSelection: [],
            current: 1,
            pageSize: 5,
            total: 0,
            value1: '',
            showAll: true//是否展开全部

        }
    },
    created() {
        this.list();
    },
    mounted() {
        /**
         * 收起搜索
         */
        this.$nextTick(function () {
            this.closeSearch();
        });
    },
    methods: {
        formatDate(date){
            return this.$moment(date).format("YYYY-MM-DD HH:mm:ss")
        },
        list() {
            this.queryParam.startTime = this.value1[0]
            this.queryParam.endTime = this.value1[1]
            logApi.logList(this.current, this.pageSize, this.queryParam).then((res) => {
                this.logList = res.data.records;
                this.pageSize = res.data.size;
                this.current = res.data.current;
                this.total = res.data.total;
            })
        },
        handleSizeChange(val) {
            this.pageSize = val;
            this.list();
        },
        handleCurrentChange(val) {
            this.current = val;
            this.list();
        },
        searchQuery() {
            this.list()
        },
        searchReset() {
            this.queryParam = {}
            this.value1 = ''
        },
        closeSearch() {
            this.showAll = !this.showAll;
            var searchBoxHeght = document.getElementById("searchBox");
            if (this.showAll == false) {
                searchBoxHeght.style.height = 60 + "px";
            } else {
                searchBoxHeght.style.height = "auto";
            }
        }
    },
    computed: {
        word: function () {
            if (this.showAll == false) {
                //对文字进行处理
                return "展开搜索";
            } else {
                return "收起搜索";
            }
        }
    },
}
</script>

<style>
#searchBox {
    overflow: hidden;
}
</style>